package com.lagou.edu.factory;

import java.lang.reflect.Method;
import java.util.List;

public class ProxyFactory {

    private final AopProxy aopProxy;

    public ProxyFactory(AopProxy aopProxy){
        this.aopProxy=aopProxy;
    }

    /**
     * 默认代理工厂
     */
    public ProxyFactory(){
        this.aopProxy=new DynamicProxy();
    }

    public Object getProxy(Object o){
        return aopProxy.createProxy(o);
    }

    /**
     *  创建带事务的代理对象
     *
     * @param o 需要代理的对象
     * @param methods 代理对象中需要代理的方法集合
     * @return 增强事务之后的代理对象
     */
    public Object getProxyWithTransaction(Object o, List<Method> methods){
        return aopProxy.createProxyWithTransaction(o,methods);
    }
}
